from random import randint
class Boxer:
    total = 0       #类属性
    @classmethod    #类方法 classMethod
    def counter(cls):
        print('there are {} boxer in this world.'.format(cls.total))
        

    def __init__(self,name):
        Boxer.total = Boxer.total + 1  #注意，实例方法怎样访问类属性
        #Boxer.total = self.total + 1  #功能同上句，为什么？实例对象名可以访问类属性。 
        #self.total = self.total + 1   # 会报错，为什么？等号是命名
        self.name = name
        self.life = 100
        self.pet = None
    def intro(self):
        if self.pet == None:
            print('my name is {},and I hate dog '.format(self.name))
        else:
            print('my name is {},and I have a dog {}'.format(self.name,self.pet.name))
    def punch(self):
        side = randint(0,1)
        print('{} puch in {} '.format(self.name,side),end='--->')
        return side
    def dodge(self):
        side = randint(0,1)
        print('{} dodge in {}'.format(self.name,side) )
        return side
    def adopt(self,dog):
        self.pet = dog
        dog.adopted(self)
    def show(self):
        print('{}={}'.format(self.name,self.life))
    
class Dog:
    def __init__(self,pname,prace):
        self.name = pname
        self.race = prace
        self.owner = None
    def bite(self,person):
        print('{} is biting {}'.format(self.name,person.name))
        person.life = person.life - 5
    def adopted(self,powner):
        self.owner = powner
    def intro(self):
        if self.owner == None:
            print('wangwang, my name is {}, I want a hoster'.format(self.name))
        else:
            print('wangwang, my name is {}, my owner is {}'.format(self.name,self.owner.name))
    



b1 = Boxer('Ali')
b2 = Boxer('tenson')
Boxer.counter()
#print('b1 acccess total = {}'.format(b1.total))

b1.total = 10
Boxer.counter()
print(b1.total)